package com.vitaf.cash.app.utils.manager

import android.graphics.Color
import android.view.View
import com.vitaf.cash.app.databinding.VitafRootViewBinding

/**
 * TitleBar管理器
 */
class VitafTitleBarManager(private val binding: VitafRootViewBinding) {

    /**
     * 设置TitleBar可见性
     * @param visibility View.VISIBLE, View.INVISIBLE 或 View.GONE
     */
    fun setVisibility(visibility: Int): VitafTitleBarManager {
        binding.rootTitleBar.visibility = visibility
        return this
    }

    /**
     * 设置背景颜色
     * @param color 颜色值
     */
    fun setBackgroundColor(color: Int): VitafTitleBarManager {
        setVisibility(View.VISIBLE)
        binding.rootTitleBar.setBackgroundColor(color)
        return this
    }

    /**
     * 设置背景资源
     * @param resId 资源ID
     */
    fun setBackgroundResource(resId: Int): VitafTitleBarManager {
        setVisibility(View.VISIBLE)
        binding.rootTitleBar.setBackgroundResource(resId)
        binding.rootTitleBar.setPadding(0, 0, 0, 0)
        return this
    }

    /**
     * 设置返回按钮可见性
     * @param visibility View.VISIBLE, View.INVISIBLE 或 View.GONE
     */
    fun setBackButtonVisibility(visibility: Int): VitafTitleBarManager {
        binding.rootBack.visibility = visibility
        return this
    }

    /**
     * 设置返回按钮图标
     * @param resId 图标资源ID
     */
    fun setBackButtonIcon(resId: Int): VitafTitleBarManager {
        setBackButtonVisibility(View.VISIBLE)
        binding.rootBack.setImageResource(resId)
        return this
    }

    /**
     * 设置返回按钮点击监听器
     * @param listener 点击监听器
     */
    fun setBackButtonClickListener(listener: View.OnClickListener): VitafTitleBarManager {
        binding.rootBack.setOnClickListener(listener)
        return this
    }

    /**
     * 设置标题可见性
     * @param visibility View.VISIBLE, View.INVISIBLE 或 View.GONE
     */
    fun setTitleVisibility(visibility: Int): VitafTitleBarManager {
        binding.rootTitle.visibility = visibility
        return this
    }

    /**
     * 设置标题文本
     * @param text 标题文本
     */
    fun setTitle(text: String): VitafTitleBarManager {
        setTitleVisibility(View.VISIBLE)
        binding.rootTitle.text = text
        return this
    }

    /**
     * 设置标题颜色
     * @param color 颜色值
     */
    fun setTitleColor(color: Int): VitafTitleBarManager {
        setTitleVisibility(View.VISIBLE)
        binding.rootTitle.setTextColor(color)
        return this
    }

    /**
     * 设置标题对齐方式
     * @param gravity 对齐方式
     */
    fun setTitleGravity(gravity: Int): VitafTitleBarManager {
        setTitleVisibility(View.VISIBLE)
        binding.rootTitle.gravity = gravity
        return this
    }

    /**
     * 设置右侧按钮可见性
     * @param visibility View.VISIBLE, View.INVISIBLE 或 View.GONE
     */
    fun setRightButtonVisibility(visibility: Int): VitafTitleBarManager {
        binding.rootCustomer.visibility = visibility
        return this
    }

    /**
     * 设置右侧按钮图标
     * @param resId 图标资源ID
     */
    fun setRightButtonIcon(resId: Int): VitafTitleBarManager {
        setRightButtonVisibility(View.VISIBLE)
        binding.rootCustomer.setImageResource(resId)
        return this
    }

    /**
     * 设置右侧按钮点击监听器
     * @param listener 点击监听器
     */
    fun setRightButtonClickListener(listener: View.OnClickListener): VitafTitleBarManager {
        binding.rootCustomer.setOnClickListener(listener)
        return this
    }

    /**
     * 设置根布局背景颜色
     * @param color 颜色值
     */
    fun setRootBackgroundColor(color: Int): VitafTitleBarManager {
        binding.rootLayout.setBackgroundColor(color)
        return this
    }

    /**
     * 设置根布局背景透明
     */
    fun setRootBackgroundTransparent(): VitafTitleBarManager {
        binding.rootLayout.setBackgroundColor(Color.TRANSPARENT)
        return this
    }

    /**
     * 设置根布局背景资源
     * @param drawableId 资源ID
     */
    fun setRootBackgroundResource(drawableId: Int): VitafTitleBarManager {
        binding.rootLayout.setBackgroundResource(drawableId)
        return this
    }
}